<%@ page pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/base/taglibs.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<link href="${ctx}/css/main.css" rel="stylesheet" type="text/css" />
	</head>
	<script language="javascript">
		var message = '${message}';
		if(message != ''){
			alert(message);
		}
	
		function submitAction(actionName){
			var typeCode = document.getElementById("typeCode").value;
			var id = document.getElementById("id").value;
			if(id == ''){
				if(typeCode == '') {
					alert('请输入类别代码');
					return;
				}
				var regexp = /^[a-zA-Z]+$/;
				if(typeCode.replace(/[^\x00-\xff]/g,"**").length != 2 || !regexp.test(typeCode)) {
					alert('请输入两位英文字母类别代码');
					return;
				}
			}
			
			if(document.getElementById("typeName").value == '') {
				alert('请输入类别名称');
				return;
			}
			document.typeForm.action = actionName ;
			document.typeForm.submit();
		}
		
		function submitDtlAction(actionName){
			if(document.getElementById("typeDtlName").value == '') {
				alert('请输入子类别名称');
				return;
			}
			document.typeForm.action = actionName ;
			document.typeForm.submit();
		}
		
		function doDelete(actionName,id){
			if(confirm('删除时该类别下的所有子类别将被删除，是否确认删除？')){
				document.getElementById("dtlId").value = id;
				document.typeForm.action = actionName ;
				document.typeForm.submit();
			}
		}
		
		function backAction(actionName){
			document.typeForm.action = actionName ;
			document.typeForm.submit();
		}
	</script>
	
	<body>
		<form method="post" action="" name="typeForm">
			<table border="0" cellspacing="1" cellpadding="3" align="center" width="100%">
				<tr>
					<td class="td11" align="left" colspan="4">
						<input type="button" name="save" value="保存" onClick="submitAction('saveTypeCode.ac');">
						&nbsp;&nbsp;<input type="button" name="back" value="返回" onClick="backAction('typeCodeManage.ac');">
					</td>
				</tr>
				<c:if test="${empty typeCode.id}">
					<tr>
						<td colspan="4"><span style="color:red">提示：类别代码栏位请输入两位英文字母</span></td>
					</tr>
				</c:if>
				<tr>
					<td width="20%" class="td2"> 
						类别代码  <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<input type="hidden" name="dtlId" size="32" value="">
						<input type="hidden" name="id" size="32" value="${typeCode.id}">
						<input type="hidden" name="levels" size="32" value="${typeCode.levels}">
						<c:if test="${empty typeCode.id}">
							<input type="text" name="typeCode" size="32" value="${typeCode.typeCode}">
						</c:if>
						<c:if test="${!empty typeCode.id}">
							<input readonly="readonly" style="color:grey" type="text" name="typeCode" size="32" value="${typeCode.typeCode}">
						</c:if>
					</td>
					<td width="20%" class="td2">
						类别名称  <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<input type="text" name="typeName" size="32" value="${typeCode.typeName}">
					</td>
				</tr>
				<c:if test="${typeCode.levels == 1}">
					<tr>
						<td width="20%" class="td2"> 
							样式 
						</td>
						<td width="30%" class="td2">
							<input type="text" name="style" size="32" value="${typeCode.style}">
						</td>
						<td width="20%" class="td2">
							层次
						</td>
						<td width="30%" class="td2">
							<c:if test="${typeCode.levels == 1}"><input readonly="readonly" style="color:grey" type="text" size="32" value="一级"></c:if>
							<c:if test="${typeCode.levels == 2}"><input readonly="readonly" style="color:grey" type="text" size="32" value="二级"></c:if>
							<c:if test="${typeCode.levels == 3}"><input readonly="readonly" style="color:grey" type="text" size="32" value="三级"></c:if>
						</td>
					</tr>
				</c:if>
				<c:if test="${typeCode.levels != 1}">
					<tr>
						<td width="20%" class="td2"> 
							层次 
						</td>
						<td width="30%" class="td2">
							<c:if test="${typeCode.levels == 1}"><input readonly="readonly" style="color:grey" type="text" size="32" value="一级"></c:if>
							<c:if test="${typeCode.levels == 2}"><input readonly="readonly" style="color:grey" type="text" size="32" value="二级"></c:if>
							<c:if test="${typeCode.levels == 3}"><input readonly="readonly" style="color:grey" type="text" size="32" value="三级"></c:if>
						</td>
						<td width="20%" class="td2">
						</td>
						<td width="30%" class="td2">
						</td>
					</tr>
				</c:if>
			</table>
			<BR>
			<c:if test="${!empty typeCode.id && typeCode.levels != 3}">
				<table border="0" cellspacing="1" cellpadding="3" align="center" width="100%">
					<tr>
						<td class="td11" align="left" colspan="4">
							<input type="button" name="save" value="添加" onClick="submitDtlAction('saveTypeCodeDtl.ac');">
						</td>
					</tr>
					<tr>
						<td width="20%" class="td2">
							子类别名称  <span style="color:red;vertical-align:middle;">*</span>
						</td>
						<td width="30%" class="td2">
							<input type="text" name="typeDtlName" size="32" value="">
						</td>
						<td width="20%" class="td2"> 
							
						</td>
						<td width="30%" class="td2">
							
						</td>
					</tr>
				</table>
				<br>
				<table border="0" cellspacing="1" cellpadding="3" align="center" width="100%">
					<tr>
						<td width="30%" class="td1" align="center">
							类别代码
						</td>
						<td width="30%" class="td1" align="center">
							类别名称
						</td>
						<td width="20%" class="td1" align="center">
							层次
						</td>
						<td width="20%" class="td1" align="center">
							删除
						</td>
					</tr>
					<c:forEach var="typeCode" items="${typeCodeList}">
						<tr>
							<td class="td2">
								${typeCode.typeCode}
							</td>
							<td class="td2">
								${typeCode.typeName}
							</td>
							<td class="td2" align="center">
								<c:if test="${typeCode.levels == 1}">一级</c:if>
								<c:if test="${typeCode.levels == 2}">二级</c:if>
								<c:if test="${typeCode.levels == 3}">三级</c:if>
							</td>
							<td class="td2" align="center">
								<img src="${ctx}/images/delete0.png" onclick="javascript:doDelete('deleteTypeCodeDtl.ac','${typeCode.id}');">
							</td>
						</tr>
					</c:forEach>
				</table>
			</c:if>
		</form>
	</body>
</html>